package com.jsy.testlock.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author: SongyangJi
 * @description:
 * @since: 2021/11/30
 */


@RestController
public class TestController {

    Random random = new Random();

    AtomicInteger count = new AtomicInteger(0);

    long start = -1;

    @GetMapping("/test")
    public boolean test() {
        if (count.getAndIncrement() == 0) {
            start = System.currentTimeMillis();
        }
        int delay = random.nextInt(200);
        try {
            Thread.sleep(delay);
        } catch (InterruptedException e) {
            System.err.println(e.getMessage());
        }
        System.out.println("now is " + Thread.currentThread().getName() + " ; to start pass " + (System.currentTimeMillis() - start) + " ms ; count is " + count.get());
        return random.nextBoolean();
    }

}
